#!/usr/bin/python

import cPickle
from llpy import csclass
from llpy import mlinear
from llpy.sutils import *
print sys.meta_path

import argparse
parser = argparse.ArgumentParser(description = "Load a classifier and dump it to disk.")
parser.add_argument('-c','--classifier',default="full",help="classifier [full|nn]")
parser.add_argument('-r','--reject',default=None,help="model for reject classifier (should have outputs method)")
parser.add_argument('-k','--k',default=None,type=int,help="k (for knn-style classifiers)")
parser.add_argument('-o','--output',help="output file")
parser.add_argument('input',help="data file")
args = parser.parse_args()


if args.classifier=="full":
    c = csclass.ProtoRejectClassifier()
    c.load(args.input)
elif args.classifier=="nn":
    c = csclass.SimpleNN()
    c.load(args.input)
elif args.classifier=="ll":
    c = csclass.LocLinClassifier()
    c.load(args.input)
elif args.classifier=="combo":
    c = csclass.ComboClassifier(args.input,args.reject)
else:
    print "unknown classifier:",args.classifier
    sys.exit(1)

if args.k is not None:
    c.set(k=args.k)

with open(args.output,"w") as stream:
    cPickle.dump(c,stream,2)
